﻿using DomainCommons.Models;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace OpenAI.Domain.Entities
{
    /// <summary>
    /// 聊天消息，用户和AI的对话，AI发送或者用户发送
    /// </summary>
    public class ChatMessage: IHasCreationTime, IHasDeletionTime, ISoftDelete
    {
        public int Id { get;}
        /// <summary>
        /// 关联聊天会话Id
        /// </summary>
        public ChatSession ChatSession { get; set; }
        /// <summary>
        /// 是否AI
        /// </summary>
        public bool IsBot { get; set; }
        /// <summary>
        /// 发送内容
        /// </summary>
        public string? Content { get; set; }
        /// <summary>
        /// 发送时间
        /// </summary>
        public DateTime CreationTime { get;private set; }

        /// <summary>
        /// 是否删除
        /// </summary>
        public bool IsDeleted { get; private set; }
        /// <summary>
        /// 删除时间
        /// </summary>

        public DateTime? DeletionTime { get; private set; }

        public void SoftDelete()
        {
            this.DeletionTime = DateTime.Now;
            IsDeleted = true;
        }

        /// <summary>
        /// AI用，给true，用户用就给false
        /// </summary>
        /// <param name="isBot"></param>
        /// <param name="content"></param>
        public ChatMessage(bool isBot,string content) : this(content)
        {
            this.IsBot = isBot;
        }
        /// <summary>
        /// 只能用户用
        /// </summary>
        /// <param name="content"></param>
        public ChatMessage(string content):this() 
        {
            this.Content = content;
        }
        public ChatMessage()
        {
            this.CreationTime = DateTime.Now;
        }
    }
}
